#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>

int find(int* arr, int n, int sz)
{
	for (int i = 0; i < sz; i++)
	{
		if (arr[i] == n)
		{
			return i;
		}
	}

	return -1;
}

void move(int* arr, int n, int sz)
{
	for (int i = n; i > 0; i--)
	{
		arr[i] = arr[i - 1];
	}
}

int main()
{
	int n = 0, m = 0;
	scanf("%d", &n);
	int* queue = (int*)malloc(sizeof(int) * n);

	for (int i = 0; i < n; i++)
	{
		scanf("%d", &queue[i]);
	}

	scanf("%d", &m);
	for (int i = 0; i < m; i++)
	{
		int num = 0, pos = 0;
		scanf("%d", &num);

		pos = find(queue, num, n);

		move(queue, pos, n);

		queue[0] = num;
	}

	for (int i = 0; i < n; i++)
	{
		if (i != n - 1)
		{
			printf("%d ", queue[i]);
		}
		else
		{
			printf("%d", queue[i]);
		}
	}

	free(queue);
	return 0;
}
